<template>
  <div>
    授权中。。。
  </div>
</template>

<script>
import {
  Toast
} from 'vant'
import { isLogin } from '@/assets/js/isLogin'
export default {
  data () {
    return {
      sessid: ''
    }
  },
  methods: {
    postToken () {
      this.$api.login.loginSucc()
        .then(this.postTokenSucc)
        .catch((e) => {
          console.log(e)
        })
    },
    postTokenSucc (res) {
      const path = this.$localStorage.get('authUrl')
      res = res.data
      if (this.$api.CODE_OK === res.code && res.data) {
        this.$localStorage.set('loginStatus', res.msg)
        const data = res.data
        this.$localStorage.set('avatar', data.avatar)
        this.$localStorage.set('userName', data.nickname)
        let date = +new Date()
        this.$localStorage.set('loginDate', date)
        this.$router.replace(path)
      } else {
        Toast({
          message: res.msg,
          duration: 1000,
          forbidClick: true
        })
        this.$localStorage.remove('loginStatus')
        this.$localStorage.remove('loginDate')
        isLogin(path)
      }
    }
  },
  activated () {
    this.postToken()
  }
}

</script>
<style lang='stylus' scoped>
</style>
